package com.meilai.project.controller.mini;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.controller.mini.dto.MiniCustomerNeedSearchParams;
import com.meilai.project.controller.mini.dto.MiniExportDataParams;
import com.meilai.project.controller.mini.dto.MiniSearchBuildingParams;
import com.meilai.project.controller.mini.dto.MiniSubmitNeedParams;
import com.meilai.project.controller.mini.service.MiniMediaPointService;
import com.meilai.project.controller.mini.vo.MiniBuildingVO;
import com.meilai.project.controller.mini.vo.MiniCustomerNeedVO;
import com.meilai.project.controller.mini.vo.MiniDistanceVO;
import com.meilai.project.controller.mini.vo.MiniSourceVO;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.dto.base.SimpleObj;
import com.meilai.project.util.ThreadLocalUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "小程序-工作台-点位")
@RestController
@RequestMapping("api/mini/media-point")
public class MiniMediaPointController {

    @Autowired
    private MiniMediaPointService service;

    @GetMapping("list-distance")
    @ApiOperation(value = "查询距离待选项")
    public ApiResult<List<MiniDistanceVO>> listDistance() {
        return ApiResult.ok(service.getDistanceList());
    }

    @GetMapping("list-area")
    @ApiOperation(value = "查询常州所有区划")
    public ApiResult<List<SimpleObj>> listArea() {
        return ApiResult.ok(service.getAreaList());
    }

    @GetMapping("list-industry")
    @ApiOperation(value = "查询所有行业")
    public ApiResult<List<SimpleObj>> listIndustry() {
        return ApiResult.ok(service.getIndustryList());
    }

    @GetMapping("list-my-customers")
    @ApiOperation(value = "查询我跟进的客户")
    public ApiResult<List<SimpleObj>> listMyCustomers() {
        return ApiResult.ok(service.listMyCustomers());
    }

    @GetMapping("list-all-media-type")
    @ApiOperation(value = "查询所有点位类型")
    public ApiResult<List<SimpleObj>> listAllMediaType() {
        return ApiResult.ok(service.listAllMediaType());
    }

    @GetMapping("list-source")
    @ApiOperation(value = "查询所有资源")
    public ApiResult<MiniSourceVO> listSource() {
        return ApiResult.ok(service.getSourceList());
    }

    @PostMapping("search-building")
    @ApiOperation(value = "查询符合条件的项目")
    public ApiResult<List<MiniBuildingVO>> searchBuilding(@Validated @RequestBody MiniSearchBuildingParams dto) {
        return ApiResult.ok(service.searchBuilding(dto));
    }

    @GetMapping("building-detail")
    @ApiOperation(value = "查询项目详情")
    public ApiResult<MiniSourceVO> buildingDetail(@RequestParam(value = "id", required = true) Long id) {
        return ApiResult.ok(service.getBuildingDetail(id));
    }

    @PostMapping("submit-customer-need")
    @ApiOperation(value = "提交客户需求")
    public ApiResult submitNeed(@Validated @RequestBody MiniSubmitNeedParams dto) {
        service.submitCustomerNeed(dto);
        return ApiResult.ok();
    }

    @GetMapping("customer-need-list")
    @ApiOperation(value = "客户需求列表分页")
    public ApiResult<Page<MiniCustomerNeedVO>> customerNeedList(@ApiParam("form") MiniCustomerNeedSearchParams params) {
        params.setCurrentUserId(ThreadLocalUserUtil.get().getId());
        Page<MiniCustomerNeedVO> vo = service.selectPageList(params);
        return ApiResult.ok(vo);
    }

    @PostMapping("export-data")
    @ApiOperation(value = "导出数据")
    public ApiResult<String> exportData(@Validated @RequestBody MiniExportDataParams dto) {
        return ApiResult.ok(service.exportData(dto), "导出成功");
    }
}
